package com.example.zhengchaojun.arcgis.basicesTest;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.esri.arcgisruntime.geometry.Geometry;
import com.esri.arcgisruntime.geometry.GeometryType;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.mapping.view.LocationDisplay;
import com.esri.arcgisruntime.mapping.view.MapScaleChangedEvent;
import com.esri.arcgisruntime.mapping.view.MapScaleChangedListener;
import com.esri.arcgisruntime.mapping.view.SketchCreationMode;
import com.esri.arcgisruntime.mapping.view.SketchEditor;
import com.esri.arcgisruntime.mapping.view.SketchGeometryChangedEvent;
import com.esri.arcgisruntime.mapping.view.SketchGeometryChangedListener;
import com.esri.arcgisruntime.mapping.view.SketchStyle;
import com.example.zhengchaojun.arcgis.ArgisMapConstant;
import com.example.zhengchaojun.arcgis.R;
import com.example.zhengchaojun.arcgis.map.BaseArcgisMapActivity;
import com.example.zhengchaojun.arcgis.view.Compass;

import java.text.DecimalFormat;

/**
 * 类描述：
 * 作者：郑朝军 on 2018/5/10
 * 邮箱：1250393285@qq.com
 * 公司：武汉智博创享科技有限公司
 * 修改人：郑朝军 on 2018/5/10
 * 修改备注：
 */
public class BasicesActivity extends BaseArcgisMapActivity
{
    public int getLayoutID()
    {
        return R.layout.activity_main;
    }

    public void initView()
    {
        super.initView();
    }

    public void initData()
    {
        showCompass();
        showScale();
        m_mapViewDelegate.updateMagnifierWihtPanMapEnabled(true);
    }

    private void showCompass()
    {
        RelativeLayout compassView = (RelativeLayout) findViewById(R.id.activity_map_compass);
        /**旋转*/
        final Compass mCompass = new Compass(this, null, m_mapView);
        mCompass.setClickable(true);
        compassView.addView(mCompass);
        mCompass.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                m_mapView.setViewpointRotationAsync(0);
                //设置旋转角度
                mCompass.setRotationAngle(0);
                //设置旋转隐藏
                mCompass.setVisibility(View.GONE);
            }
        });
    }

    private void showScale()
    {
        /**显示比例尺级别*/
        final TextView textView = (TextView) findViewById(R.id.activity_map_mapview_scale);
        final DecimalFormat df = new DecimalFormat("###");
        //设置默认比例尺级别
        String scale = df.format(m_mapView.getMapScale());
        textView.setText("比例尺 1:" + scale);
        m_mapView.addMapScaleChangedListener(new MapScaleChangedListener()
        {
            @Override
            public void mapScaleChanged(MapScaleChangedEvent mapScaleChangedEvent)
            {
                String scale = df.format(m_mapView.getMapScale());
                textView.setText("比例尺 1:" + scale);
            }
        });
    }

    public void onClick(View view)
    {
        switch (view.getId())
        {
            case R.id.zoomin:
                updateLevelZoomIn();
                break;
            case R.id.zoomout:
                updateLevelZoomOut();
                break;
            case R.id.location_mine:
                doClickLocationMine();
                break;
        }
    }

    private void doClickLocationMine()
    {
        LocationDisplay locationDisplayManager =  m_mapView.getLocationDisplay();//获取定位类
        locationDisplayManager.setShowLocation(true);
        locationDisplayManager.setAutoPanMode(LocationDisplay.AutoPanMode.COMPASS_NAVIGATION);//设置模式
        locationDisplayManager.startAsync();//开始定位
    }
}
